package com.msk.framework.web.utils;

import com.msk.base.domain.goodsMember.GoodsMember;
import com.msk.base.service.goodsMember.GoodsMemberService;
import com.msk.common.core.domain.model.LoginUser;
import com.msk.common.utils.ServletUtils;
import com.msk.common.utils.StringUtils;
import com.msk.common.utils.spring.SpringUtils;
import com.msk.framework.web.service.TokenService;
import com.msk.wlhy.domain.HtDriverFile;
import com.msk.wlhy.domain.HtSupplier;
import com.msk.wlhy.service.HtDriverFileService;
import com.msk.wlhy.service.HtSupplierService;

import java.util.Map;

/**
 * @Description 获取当前登录信息
 * @Author zlf
 * @Date 2023/5/10 14:34
 */
public class TokenUtils {
    
    private static TokenService tokenService = SpringUtils.getBean(TokenService.class);
    
    private static HtDriverFileService htDriverFileService = SpringUtils.getBean(HtDriverFileService.class);

    private static GoodsMemberService goodsMemberService = SpringUtils.getBean(GoodsMemberService.class);

    private static HtSupplierService htSupplierService = SpringUtils.getBean(HtSupplierService.class);

    /**
     * 获取当前token用户信息
     * @return
     */
    public static LoginUser getMpLoginUser() {
        LoginUser mpLoginUser = tokenService.getMpLoginUser(ServletUtils.getRequest());
        return mpLoginUser;
    }

    /**
     * 获取当前登录司机信息
     * @return
     */
    public static HtDriverFile getDriverLogin() {
        HtDriverFile driverInfo = null;
        LoginUser mpLoginUser = getMpLoginUser();
        if (StringUtils.isNotNull(mpLoginUser) && "1".equals(mpLoginUser.getLoginObject())) {
            String userId = mpLoginUser.getLoginId();
            driverInfo = htDriverFileService.getDriverByUserId(userId);
        }
        return driverInfo;
    }

    /**
     * 获取当前登录货主信息
     * @return
     */
    public static Map<String,Object> getGoodsMemberLogin() {
        Map<String,Object> goodsMember = null;
        LoginUser mpLoginUser = getMpLoginUser();
        if (StringUtils.isNotNull(mpLoginUser) && "2".equals(mpLoginUser.getLoginObject())) {
            String userId = mpLoginUser.getLoginId();
            goodsMember = goodsMemberService.selectGoodsMemberInfoById(null,userId);
        }
        return goodsMember;
    }

    /**
     * 获取当前登录承运商信息
     * @return
     */
    public static HtSupplier getSupplierLogin() {
        HtSupplier supplier = null;
        LoginUser mpLoginUser = getMpLoginUser();
        if (StringUtils.isNotNull(mpLoginUser) && "3".equals(mpLoginUser.getLoginObject())) {
            String userId = mpLoginUser.getLoginId();
            supplier = htSupplierService.getHtSupplierByUserId(userId);
        }
        return supplier;
    }
}
